﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;

namespace Paltop_.Controllers
{
    public class PhotoViewerController
    {

        public List<Paltop_DatabaseLayer.FileAndFolder_View> PhotoList(int fileInfoID, int userID)
        {
            try
            {
                Paltop_DatabaseLayer.PaltopDatabaseEntities pde = new Paltop_DatabaseLayer.PaltopDatabaseEntities();
                var b = pde.FileAndFolder_View.Where(p => p.FileInfoID == fileInfoID && p.AccountID == userID);
                var currentPic = b.FirstOrDefault();

                int pID = (int)currentPic.ParentID;
                var c = pde.FileAndFolder_View.Where(p => p.ParentID == pID && p.AccountID == userID && (p.ExtentionTitle == "jpg" || p.ExtentionTitle == "gif" || p.ExtentionTitle == "bmp" || p.ExtentionTitle == "png" || p.ExtentionTitle == "tif"));
                c.OrderBy(e => e.Title);
                var t = c.ToList();
                for (int i = 0; i < t.Count; i++)
                {
                    if (t[i].FileInfoID == fileInfoID)
                    {
                        var temp = t[i];
                        t[i] = t[0];
                        t[0] = temp;
                    }
                }
                return t.ToList();
            }
            catch (Exception)
            {

                return null;
            }
        }
        public Paltop_DatabaseLayer.FileAndFolder_View MovieList(int fileInfoID, int userID)
        {
            try
            {
                Paltop_DatabaseLayer.PaltopDatabaseEntities pde = new Paltop_DatabaseLayer.PaltopDatabaseEntities();
                var b = pde.FileAndFolder_View.Where(p => p.FileInfoID == fileInfoID && p.AccountID == userID);
                var currentMovie = b.FirstOrDefault();
                return currentMovie;

            }
            catch (Exception)
            {

                return null;
            }

        }

    }
}
